package com.aho.app.util;

import android.view.animation.Interpolator;

public class InterpolateAnimation extends AbstractAnimation {
	private float mFromDeg;
	private float mToDeg;
	
	public InterpolateAnimation(float fromDeg, float toDeg, int duration, Interpolator interpolator) {
		super(duration, interpolator);
		mFromDeg = fromDeg;
		mToDeg = toDeg;
	}
	
	public float interpolate() {
		if (isPlaying()) {
			final long timestamp = System.currentTimeMillis();
			final float t = (timestamp - mStartTimestamp) / (float)mDuration; 
			final float val = mInterpolator.getInterpolation(t);
			float deg;
			if (mReverse) {
				deg = mToDeg + val * (mFromDeg - mToDeg);
			} else {
				deg = mFromDeg + val * (mToDeg - mFromDeg);
			}
			if (1.0f <= t) {
				mPlaying = false;
			}
			return deg;
		} else {
			return mReverse ? mFromDeg : mToDeg;
		}
	}
}
